<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head th:replace="common/form :: head"></head>
	<body class="mainbody">
		<form method="POST" th:object="${obj}" onsubmit="valPermission();">
			<div th:replace="common/form :: location('角色管理',*{id} gt 0 ?'修改角色信息':'新增角色')"></div>
			<div id="floatHead" class="content-tab-wrap">
			  <div class="content-tab">
			    <div class="content-tab-ul-wrap">
			      <ul>
			        <li><a href="javascript:;">角色信息</a></li>
			      </ul>
			    </div>
			  </div>
			</div>
			<div class="tab-content">
				<dl>
					<dt>中文名称</dt>
				    <dd>
				      <input type="text" class="input normal" data-type="*1-10" th:field="*{name}" />
				      <span class="Validform_checktip">*角色名称，不超过10个字符</span>
				    </dd>
				</dl>
				<dl>
					<dt>英文名称</dt>
				    <dd>
				      <input type="text" class="input normal" data-type="*1-20" th:field="*{ename}" />
				      <span class="Validform_checktip">*英文名称，不超过20个字符</span>
				    </dd>
				</dl>
				<dl>
					<dt>是否可用</dt>
				    <dd>
				    	<div class="rule-single-checkbox">
				    		<input type="checkbox" th:field="*{usable}" />
				    	</div>
				    </dd>
				</dl>
				<dl>
					<dt>备注信息</dt>
					<dd>
						<textarea class="input normal" maxlength="50" rows="5" th:field="*{remarks}"></textarea>
						<span class="Validform_checktip"></span>
					</dd>
				</dl>
				<dl>
					<dt>管理权限</dt>
					<dd>
						<table class="border-table" style="width:98%;">
							<thead>
								<tr>
									<th width="30%">名称</th>
									<th>权限分配</th>
									<th width="10%">全选</th>
								</tr>
							</thead>
							<tbody>
								<tr th:each="p,pStat:*{permissions}">
									<td>
										<span style="display:inline-block;" th:styleappend="'width:'+${#strings.arraySplit(p.menu.path,',').length-1}*20+'px'"></span>
										<span class="folder-line"></span>
										<span class="folder-open"></span>
										<span th:text="${p.menu.name}"></span>
									</td>
									<td>
										<span class="cbllist" th:with="pm=${p.menu.permission}?:0,pr=${p.permission}?:0">
											<input type="hidden" th:name="'permissions['+${pStat.count-1}+'].id'" th:value="${p.id}" th:if="${p.id!=null}" />
											<input type="hidden" th:name="'permissions['+${pStat.count-1}+'].menu.id'" th:value="${p.menu.id}" />
											<input type="hidden" th:name="'permissions['+${pStat.count-1}+'].permission'" />
											<input type="checkbox" th:if="${pm}%2>0" value="1" th:checked="${pr}%2>0" />
											<label for="permission" th:if="${pm}%2>0">查看</label>
											<input type="checkbox" th:if="${pm}%4>1" value="2" th:checked="${pr}%4>1" />
											<label for="permission" th:if="${pm}%4>1">添加</label>
											<input type="checkbox" th:if="${pm}%8>3" value="4" th:checked="${pr}%8>3" />
											<label for="permission" th:if="${pm}%8>3">修改</label>
											<input type="checkbox" th:if="${pm}%16>7" value="8" th:checked="${pr}%16>7" />
											<label for="permission" th:if="${pm}%16>7">删除</label>
										</span>
									</td>
									<td align="center">
										<input type="checkbox" class="checkall" />
									</td>
								</tr>
							</tbody>
						</table>
					</dd>
				</dl>
			</div>
			<div th:replace="common/form :: footer"></div>
		</form>
		<script type="text/javascript" th:inline="javascript">
		/*<![CDATA[*/
		function valPermission(){
			$("tbody tr").each(function(){
				var sum=0;
				var td=$(this).find("td").eq(1);
				td.find(":checked").each(function(){
					sum+=parseInt($(this).val());
				});
				td.find("[name$=permission]").val(sum);
			})
		}
		$(".checkall").click(function(){
			var $this=$(this);
			$this.parents("tr").find(":checkbox").prop("checked",$this.prop("checked"));
		});
		/*]]>*/
		</script>
		<script type="text/javascript" th:replace="common/form :: formscript"></script>
	</body>
</html>